//
//  LCViewController.m
//  Our Big Demo
//
//  Created by 刘臣 on 16/3/24.
//  Copyright © 2016年 WJP. All rights reserved.
//

#import "LCViewController.h"
#import "LCview.h"
@interface LCViewController ()<GUIPlayerViewDelegate>
@property (strong, nonatomic) GUIPlayerView *playerView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (weak, nonatomic) IBOutlet UITableView *kScrollView;

@end

@implementation LCViewController
@synthesize playerView;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self JsonWithData];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(GoBackToOne)];
    // Do any additional setup after loading the view from its nib.
}
- (void) JsonWithData {
    self.dataArray = [NSMutableArray new];
    NSString *string = @"http://app.vmoiver.com/apiv3/post/view?postid=";
    NSString *UrlString = [string stringByAppendingString:self.getString];
    [[GiveMeHleper defaultCDHttpHelper] get:UrlString params:nil success:^(id responseObj) {
        NSError *error = nil;
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableLeaves error:&error];
        
        NSArray *array = dic[@"data"][@"content"][@"video"];
        for (NSDictionary *dic in array) {
            UseModle *modle = [UseModle new];
            [modle setValuesForKeysWithDictionary:dic];
            [self.dataArray addObject:modle];
            CGFloat width = [UIScreen mainScreen].bounds.size.width;
            playerView = [[GUIPlayerView alloc] initWithFrame:CGRectMake(0, 64, width, width * 9.0f / 16.0f)];
            [playerView setDelegate:self];
            NSLog(@"%@",self.dataArray);
            [[self view] addSubview:playerView];
            NSURL *URL = [NSURL URLWithString:modle.qiniu_url];
            [playerView setVideoURL:URL];
            [playerView prepareAndPlayAutomatically:YES];
        }
        [self.kScrollView reloadData];
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];

}
- (void) GoBackToOne {
    [playerView clean];
    playerView = nil;
    [self.navigationController popToRootViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
